package com.jic.market.impl.skill;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.entity.skill.ActivitySkillGoodsConfig;
import com.jic.market.mapper.skill.ActivitySkillGoodsConfigMapper;
import com.jic.market.service.skill.ActivitySkillGoodsConfigService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 秒杀活动商品基础配置表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-12 05:22:15
 */
@Service
public class ActivitySkillGoodsConfigServiceImpl implements ActivitySkillGoodsConfigService {

    @Autowired
    private ActivitySkillGoodsConfigMapper activitySkillGoodsConfigMapper;

    @Override
    public long insert(ActivitySkillGoodsConfig activitySkillGoodsConfig) {
        activitySkillGoodsConfig.setDeleteFlag(false);
        long flag = activitySkillGoodsConfigMapper.insert(activitySkillGoodsConfig);
        return flag;
    }

    @Override
    public long delete(String promotionId) {
        return activitySkillGoodsConfigMapper.delete(promotionId);
    }

    @Override
    public long deleteById(Long id) {
        return activitySkillGoodsConfigMapper.deleteById(id);
    }

    @Override
    public long update(ActivitySkillGoodsConfig activitySkillGoodsConfig) {
        return activitySkillGoodsConfigMapper.update(activitySkillGoodsConfig);
    }

    @Override
    public ActivitySkillGoodsConfig queryByPrimaryKey(Long id) {
        return activitySkillGoodsConfigMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<ActivitySkillGoodsConfig> query(ActivitySkillGoodsConfig activitySkillGoodsConfig) {
        return activitySkillGoodsConfigMapper.query(activitySkillGoodsConfig);
    }

    @Override
    public PageResult<ActivitySkillGoodsConfig> queryPage(ActivitySkillGoodsConfig activitySkillGoodsConfig, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<ActivitySkillGoodsConfig> list = activitySkillGoodsConfigMapper.queryPage(startIndex, pageQuery.getLimit(), activitySkillGoodsConfig);
        long count = activitySkillGoodsConfigMapper.queryPageCount(activitySkillGoodsConfig);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public long deleteByPromotionIdAndGoodsId(String promotionId, String goodsId,String timeId) {
        return activitySkillGoodsConfigMapper.deleteByPromotionIdAndGoodsId(promotionId,goodsId, timeId);
    }

    @Override
    public List<ActivitySkillGoodsConfig> queryGoodsInfoByTimeId(String promotionId, String timeId, Integer start , Integer limit) {
        return activitySkillGoodsConfigMapper.queryGoodsInfoByTimeId(promotionId,timeId,start,limit);
    }

    @Override
    public long deleteGoodsByPromotionIdAndMerchantId(String promotionId, String merchantId) {
        return activitySkillGoodsConfigMapper.deleteGoodsByPromotionIdAndMerchantId(promotionId,merchantId);
    }

    @Override
    public long deleteGoodsByPromotionIdAndStoreId(String promotionId, String storeId) {
        return activitySkillGoodsConfigMapper.deleteGoodsByPromotionIdAndStoreId(promotionId,storeId);
    }

    @Override
    public long deleteGoodsByPromotionIdAndTimeId(String promotionId, String timeId) {
        return activitySkillGoodsConfigMapper.deleteGoodsByPromotionIdAndTimeId(promotionId,timeId);
    }

    @Override
    public Long queryGoodsInfoByTimeIdTotal(String promotionId, String skillTimeId) {
        return activitySkillGoodsConfigMapper.queryGoodsInfoByTimeIdTotal(promotionId,skillTimeId);
    }

    @Override
    public Long queryGoodsInfoByTimeIdSkuTotal(String promotionId, String skillTimeId) {
        return activitySkillGoodsConfigMapper.queryGoodsInfoByTimeIdSkuTotal(promotionId,skillTimeId);
    }
}